package com.aizhixin.lab.course.course.repository;

import com.aizhixin.lab.course.course.entity.CourseChapterFile;
import com.aizhixin.lab.course.template.entity.Template;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CourseChapterFileRepository extends JpaRepository<CourseChapterFile, Long> {
    CourseChapterFile findByIdAndDeleteFlag(Long id, Integer deleteFlag);

    Page<CourseChapterFile> findByChapterIdAndDeleteFlagOrderByNo(Pageable pageable, Long chapterId, Integer deleteFlag);

    List<CourseChapterFile> findByChapterIdAndDeleteFlagOrderByNo(Long chapterId, Integer deleteFlag);

    List<CourseChapterFile> findByChapterIdAndIsHideAndDeleteFlagOrderByNo(Long chapterId, Boolean isHide, Integer deleteFlag);

    List<CourseChapterFile> findByTypeAndDeleteFlag(Integer type, Integer deleteFlag);

    List<CourseChapterFile> findByFileUrlStartingWithAndDeleteFlag(String name, Integer deleteFlag);

    /**
     * 获取文件数量
     *
     * @param chapterId  章节Id
     * @param type       文件类型
     * @param deleteFlag 是否删除
     * @return
     */
    Integer countByChapterIdAndTypeAndDeleteFlag(Long chapterId, Integer type, Integer deleteFlag);
}
